import type { Product } from './type'
import request from '@/utils/request'

enum API {
  PAGE = '/product/page',
  ADD = '/product/add',
  UPDATE = '/product/update',
  DELETE = '/product/delete',
  GET_BY_ID = '/product/getById',
  IMPORT = '/product/import',
}

export function productPage(data: Product) {
  return request<any, PageResult<Product[]>>({
    url: API.PAGE,
    method: 'post',
    data,
  })
}

export function addProduct(data: Product) {
  return request<string>({
    url: API.ADD,
    method: 'post',
    data,
  })
}

export function updateProduct(data: Product) {
  return request<string>({
    url: API.UPDATE,
    method: 'post',
    data,
  })
}

export function deleteProduct(ids: number[]) {
  return request<string>({
    url: `${API.DELETE}/${ids}`,
    method: 'post',
  })
}

export function getById(id: number) {
  return request<Product>({
    url: `${API.GET_BY_ID}/${id}`,
    method: 'get',
  })
}

export function importExcel(formData: FormData) {
  return request<string>({
    url: API.IMPORT,
    method: 'post',
    data: formData,
    headers: {
      'Content-Type': 'multipart/form-data',
    },
  })
}
